package com.ruoyi.common.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

@Data
public class BalanceEntity {

    private int id;

    private int userId;

    /**
     * 当前用户的剩余token数量，-1表示无限制
     * */
    private long tokens;

    /**
     * 普通聊天次数，例如GPT3.5
     * */
    private long chatCount;

    /**
     * 高级聊天次数，例如GPT4
     * */
    private long advancedChatCount;

    /**
     * 绘画次数
     * */
    private long drawCount;


    private int sourceId;

    private int calcTypeId;

    private int orderPackageId;

    private int redeemCodeId;

    private Source source;

    private PackageEntity.CalcType calcType;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date expireTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date updateTime;

    private int state;

    private boolean expired;// 是否过期，动态判断

    public enum Source {
        Register(1, "注册"),
        SignInDaily(2, "每日签到"),
        Invite(3, "邀请新用户"),
        Buy(4, "购买"),
        AdminManual(5, "后台操作"),
        RedeemCode(6, "兑换码");

        private final int code;

        private final String desc;

        Source(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }


    public static Source getSource(int code) {
        for (Source type : Source.values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        return null;
    }

    public static final int STATE_DRAFT = 0; // 草稿状态，如支付中
    public static final int STATE_NORMAL = 1; // 这是一个可以被扣除的状态
    public static final int STATE_DISABLED = 2; // 这是废弃状态，管理员有权废弃一个balance，废弃后不可用
}
